package com.aaa.system.Controller.Api;

import com.aaa.entity.Menu;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.MenuService;
import com.aaa.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/api/menu")
public class ApiMenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 左侧菜单查询
     * @return
     */
    @GetMapping("/leftMenu")
    public Result<List<Menu>> getMenu(){
        return menuService.getLeftMenu();
    }

    /**
     * 查询树状菜单
     * @return
     */
    @GetMapping("/list")
    public Result<List<Menu>> getAllMenu(){
        return menuService.getAllMenu();
    }

    /**
     * 查询角色拥有的菜单
     * @param roleId
     * @return
     */
    @GetMapping("findByRoleId/{roleId}")
    public Result<List<Integer>> getMenuByRoleId(@PathVariable Long roleId){
        return menuService.findByRoleId(roleId);
    }

    /**
     * 修改角色的权限
     * @param roleId
     * @param menuIds
     * @return
     */
    @PostMapping("confirmMenu")
    @Log(title = "修改角色的权限",business_type = "2")
    public Result<String> confirmMenu(Long roleId,Long[] menuIds){
        return menuService.confirmMenu(roleId,menuIds);
    }

    /**
     * 查询菜单数据+模糊
     */
    @PostMapping("getList")
    public Result<List<Menu>> getList(@RequestBody Menu menu){
        return menuService.getMenuList(menu);
    }

    /**
     * 添加菜单 修改菜单
     * @param menu
     * @return
     */
    @PostMapping("saveOrUpdateMenu")
    @Log(title = "添加/修改菜单",business_type = "1")
    public Result<Boolean> saveOrUpdateMenu(@RequestBody Menu menu){
        return menuService.saveOrUpdateMenu(menu);
    }
    /**
     * 删除菜单
     */
    @DeleteMapping("delMenu/{menuId}")
    @Log(title = "删除菜单",business_type = "3")
    public Result<Boolean> delMenu(@PathVariable Long menuId){
        return menuService.delOneMenu(menuId);
    }
}
